﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using TSMUI = Tekla.Structures.Model.UI;
using TSM = Tekla.Structures.Model;
using T3D = Tekla.Structures.Geometry3d;

namespace TelaOpenTool
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();

            TriggerCommand();
        }

        private void TriggerCommand()
        {
            this.CreateBeam_button.Click += (s, e) => this.CreateSteel();
            this.CreateColumn_button.Click += (s, e) => this.CreateColumn();
            this.Connection_button.Click += (s, e) => ModelTool.BeamTool.CreateConnection();
            this.Bolt_button.Click += (s, e) => ModelTool.BeamTool.CreateBolt();
            this.MirrorPart_button.Click += (s, e) => MirrorPart();


            this.cadObj_button.Click += (s, e) => CreateCadObj();
            this.selectCadObj_button.Click += (s, e) => SelectCadObj();

            this.PrePlate_button.Click += (s, e) => ModelTool.BeamTool.CreatePlateWithRebar();
            this.PreBeam_button.Click += (s, e) => ModelTool.BeamTool.CreatePreBeam(new T3D.Point(),new T3D.Point(3000,0,0));
        }

        #region 建模
        /// <summary>
        /// 创建钢梁
        /// </summary>
        private void CreateSteel()
        {
            ModelTool.Data.SteelBeamData steelBeamData = new ModelTool.Data.SteelBeamData()
            {
                StartPoint = new Tekla.Structures.Geometry3d.Point(),
                EndPoint = new Tekla.Structures.Geometry3d.Point(1000, 0, 0),
                Material = "Q235B",
                Profile = "HN400*200*8*13",
            };
            ModelTool.BeamTool.CreateSteelBeam(steelBeamData);
        }

        /// <summary>
        /// 创建钢柱
        /// </summary>
        private void CreateColumn()
        {
            ModelTool.Data.SteelColumnData steelColumnData = new ModelTool.Data.SteelColumnData()
            {
                StartPoint = new Tekla.Structures.Geometry3d.Point(),
                EndPoint = new Tekla.Structures.Geometry3d.Point(0, 0, 1000),
                Material = "Q235B",
                Profile = "HN400*200*8*13",
            };
            ModelTool.BeamTool.CreateSteelColumn(steelColumnData);
        }

        /// <summary>
        /// 镜像对象
        /// </summary>
        private void MirrorPart()
        {
            try
            {
                var picker = new TSMUI.Picker();
                // 选择对象
                var pickedPart = picker.PickObject(TSMUI.Picker.PickObjectEnum.PICK_ONE_PART) as TSM.Part;
                var pickerPoints = picker.PickPoints(TSMUI.Picker.PickPointEnum.PICK_TWO_POINTS);
                if (pickerPoints == null || pickerPoints.Count != 2)
                {
                    return;
                }

                var Point_1 = pickerPoints[0] as T3D.Point;
                var Point_2 = pickerPoints[1] as T3D.Point;
                bool result = ModelTool.BeamTool.MirrorPart(pickedPart, new T3D.Line(Point_1, Point_2));
            }
            catch (Exception)
            {
            }
        }

        #endregion 建模

        #region cad
        private void CreateCadObj()
        {
            try
            {
                bool result = new Cad2018Tool.CadTool().CreateLine();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        private void SelectCadObj()
        {
            try
            {
                double radius = 0;
                double[] centerPoint;
                new Cad2018Tool.CadTool().SelectObj(out radius, out centerPoint);

                MessageBox.Show($"radius={radius},x={centerPoint[0]},y={centerPoint[1]}");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion cad



    }
}
